<template>
  <div>
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <template v-if="toggleSearchStatus">
              <a-col :md="6" :sm="8">
                <a-form-item label="科室序号">
                  <a-input placeholder="请输入科室序号" v-model="queryParam.depId"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-item label="科室代码">
                  <a-input placeholder="请输入科室代码" v-model="queryParam.depCode"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-item label="科室名称">
                  <a-input placeholder="请输入科室名称" v-model="queryParam.depName"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-item label="科室简称">
                  <a-input placeholder="请输入科室简称" v-model="queryParam.depAbb"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="8" style="float: left;overflow: hidden;">
                <a-form-item label="科室床位">
                  <a-input placeholder="请输入科室床位" v-model="queryParam.depBed"></a-input>
                </a-form-item>
              </a-col>
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
            </template>
          </a-row>
        </a-form>
      </div>

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        <a-button type="primary" icon="delete" @click="batchDel">批量删除</a-button>
        <a-button type="primary" icon="play-circle-o">启用</a-button>
        <a-button type="primary" icon="pause-circle">停用</a-button>
        <a-button type="primary" v-print="'#printContent'" icon="printer">打印</a-button>
        <!--<a-button type="primary" icon="logout">退出</a-button>-->
        <a-button
          type="primary"
          @click="handleToggleSearch"
          icon="search"
        >{{ toggleSearchStatus ? '收起查询' : '展开查询' }}</a-button>
        <a-button type="primary" v-if="type" icon="download" @click="handleExportXls('科室设置')">导出</a-button>
        <a-upload
          name="file"
          :showUploadList="false"
          :multiple="false"
          :headers="tokenHeader"
          :action="importExcelUrl"
          @change="handleImportExcel"
          v-if="type"
        >
          <a-button type="primary" icon="import">导入</a-button>
        </a-upload>
        <a style="margin-left: 8px" @click="changetype">
          {{ type ? '收起' : '展开' }}
          <a-icon :type="type ? 'left' : 'right'" />
        </a>
      </div>

      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          id="printContent"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange"
        >
          <span slot="underSetting">
            <p>科别</p>
          </span>
          <span slot="action" slot-scope="text, record">
            <a @click="startOrOut(url.queryStop,record)" v-if="record.stopType==2">启动<a-divider type="vertical" /></a>
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" />
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a>删除</a>
            </a-popconfirm>
          </span>
          <template slot="customRenderStatus" slot-scope="stopType, record">
            <a-tag v-if="stopType==1" @click="startOrOut(url.queryStop,record)" color="green">已启用</a-tag>
            <a-tag v-if="stopType==2" @click="startOrOut(url.queryStop,record)" color="orange">已停用</a-tag>
          </template>
          <template slot="depCategorynext" slot-scope="stopType">
            <span v-if="stopType==1">门诊</span>
            <span v-if="stopType==2">观察室</span>
            <span v-if="stopType==3">家庭病床</span>
          </template>
          <template slot="underSettingnext" slot-scope="stopType">
            <span v-if="stopType==1">门诊</span>
            <span v-if="stopType==2">住院</span>
            <span v-if="stopType==3">医技</span>
          </template>
        </a-table>
      </div> 
      <!-- table区域-end -->

      <!-- 表单区域 -->
      <depsetting-modal ref="modalForm" @ok="modalFormOk"></depsetting-modal>
    </a-card>
    <company-profile />
  </div>
</template>

<script>
import DepsettingModal from './modules/DepsettingModal'
import { JeecgListMixin } from '@/mixins/zkxhListMixins'
import { getAction } from '@/api/manage'
import CompanyProfile from '../../components/knowlage/companyProfile'
export default {
  name: 'DepsettingList',
  mixins: [JeecgListMixin],
  components: {
    DepsettingModal,
    CompanyProfile
  },
  data() {
    return {
      type: false,
      description: '科室设置管理页面',
      // 这是科室设置页面，模板页面编辑
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 30,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '序号',
          align: 'center',
          dataIndex: 'depId'
        },
        {
          title: '科室代码',
          align: 'center',
          dataIndex: 'depCode'
        }, 
        {
          title: '科室名称',
          align: 'center',
          dataIndex: 'depName'
        },
        {
          title: '科室简称',
          align: 'center',
          dataIndex: 'depAbb'
        },
        {
          title: '科室床位',
          align: 'center',
          dataIndex: 'depBed'
        },
        {
          title: '科目',
          align: 'center',
          dataIndex: 'subject'
        },
        {
          title: '病区名称',
          align: 'center',
          dataIndex: 'inpatientArea'
        },
        {
          title: '归口设置',
          align: 'center',
          dataIndex: 'underSetting',
          scopedSlots: { customRender: 'underSettingnext' },
        },
        {
          title: '科室类别',
          align: 'center',
          dataIndex: 'depCategory',
          scopedSlots: { customRender: 'depCategorynext' },
        },
        {
          title: '拼音码',
          align: 'center',
          dataIndex: 'pinyinCode'
        },
        {
          title: '字典码',
          align: 'center',
          dataIndex: 'dicCode'
        },
        {
          title: '使用状态',
          align: 'center',
          dataIndex: 'stopType',
          scopedSlots: { customRender: 'customRenderStatus' },
          //filters: [{ text: '已启动', value: '1' }, { text: '已暂停', value: '2' }]
        },
        {
          title: '操作人',
          align: 'center',
          dataIndex: 'operator'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/dicts/depsetting/list',
        delete: '/dicts/depsetting/delete',
        pause: '/dicts/depsetting/pause',
        resume: '/dicts/depsetting/resume',
        deleteBatch: '/dicts/depsetting/deleteBatch',
        exportXlsUrl: '/dicts/depsetting/exportXls',
        importExcelUrl: '/dicts/depsetting/importExcel',
        queryStop: '/dicts/depsetting/queryStop'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    changetype() {
      this.type = !this.type
    },
    outOrStart(requestUrl,data){
      this.startOrOut(requestUrl,data);
    }
  }
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
/deep/ .ant-modal-content {
  background-color: cyan;
}
/deep/ .ant-input:hover{
  border-color: none;
}
</style>